/**

 */

var searchString;

function showSearchPopup()
{
    var dctk = connected.toolkit;
    
    // create a new panel for the popup
    var popup = dctk.createPanelCtrl("popup", true);
    popup.width = 240;
    popup.height = 80;
    popup.outlined = true;
    popup.filled = true;
    popup.color.rgb = 0x000000;
    popup.color.a = 192;
    popup.onUnhandledKeyEvent = popupSearchButtonHandler;
    
    var searchStringTxt = dctk.createLabelCtrl("searchStringTxt", true);
    searchStringTxt.setRect(0, 50, 82, 70);
    searchStringTxt.textColor.rgb = 0xCDCDCD;
    searchStringTxt.fontSize = 18;
	searchStringTxt.align = dctkLabel.TS_RIGHT;
	searchStringTxt.valign = dctkLabel.TS_MIDDLE;
    searchStringTxt.text = "Search:";
    popup.addChild(searchStringTxt);
	
	var keyboardTxt = dctk.createLabelCtrl("keyboardTxt", true);
    keyboardTxt.setRect(0, 28, 240, 48);
    keyboardTxt.textColor.rgb = 0xCDCDCD;
    keyboardTxt.fontSize = 14;
	keyboardTxt.align = dctkLabel.TS_CENTER;
	keyboardTxt.valign = dctkLabel.TS_MIDDLE;
    keyboardTxt.text = "Press ENTER for the keyboard.";
    popup.addChild(keyboardTxt);

    var searchStringEdit = dctk.createEditCtrl("searchStringEdit", true);
    searchStringEdit.setRect(87, 50, 227, 70);
    searchStringEdit.text = searchString;
    searchStringEdit.fontSize = 20;
    searchStringEdit.numeric = false;
    popup.addChild(searchStringEdit);

	var okBtn = dctk.createButtonCtrl("okBtn", true);
    okBtn.setRect(87, 10, 173, 25);
    okBtn.text = "OK";
    okBtn.fontSize = 16;
    okBtn.onSelect = function(e) { fetchNewSearchResults(); dctk.dismissPopup(); }
    popup.addChild(okBtn);
	    
    // show the popup
    dctk.invokePopup(popup);
    
	// set siblings
	searchStringEdit.bottomSibling = okBtn;
	okBtn.topSibling = searchStringEdit;
	
	dctk.focusedElement = searchStringEdit;
}

function popupSearchButtonHandler(e)
{
    var dctk = connected.toolkit;

    switch(e.buttonId)
    {
        case dcKeyEvent.BUTTON_ID_BACK:
        {
            dctk.dismissPopup();
        }
        break;

        case dcKeyEvent.BUTTON_ID_SELECT:
        {
            fetchNewSearchResults();
            dctk.dismissPopup();
        }
        break;
    }
}

function fetchNewSearchResults()
{
    var dctk = connected.toolkit;
    var searchStringEdit = dctk.getElementById("searchStringEdit");   
    
    searchString = searchStringEdit.text;
	feed = "http://www.hulu.com/feed/search/"+searchString;
	feedTitle = "RESULTS FOR '"+searchString+"'"
	state = "";
	doVideoLayout();
}




